
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="admin" />
        <title>Edit User</title>
    </head>
    <body>
		<div id="center-column">
			<div class="top-bar">
				<g:link class="button" action="create">ADD NEW</g:link>
				<h1>Edit User</h1>
				<div class="breadcrumbs">
					<a class="home" href="${resource(dir:'')}">Home</a> / 
					<g:link class="list" action="list">User List</g:link> /
					<g:link class="create" action="create">New User</g:link>
				</div>
			</div><br />
			<div class="select-bar-border-no"></div>
	        <div class="body">
	                <div class="dialog">
                        <g:form name="userForm" controller="user" method="post" >
                            <input type="hidden" name="id" value="${user?.id}" />
			            <div class="subdialog">
			            	<h2>User</h2>
							<p>
	                            <label for="username">Username:</label>
	                            <span id="username">${user.username}</span>
							</p>
							<p class='value ${hasErrors(bean:user,field:'password','errors')}'>
	                           <label for='password'>password:</label>
	                           <input type="password" id='password' name='password' value="${user?.password?.encodeAsHTML()}"/>
							</p>
							<p class='value ${hasErrors(bean:user,field:'firstname','errors')}'>
	                           <label for='firstname'>Firstname:</label>
	                           <input type="text" id='firstname' name='firstname' value="${user?.firstname?.encodeAsHTML()}"/>
							</p>
							<p class='value ${hasErrors(bean:user,field:'lastname','errors')}'>
	                           <label for='lastname'>Lastname:</label>
	                           <input type="text" id='lastname' name='lastname' value="${user?.lastname?.encodeAsHTML()}"/>
							</p>
							<p class='value ${hasErrors(bean:address,field:'street','errors')}'>
					        	<label for='street'>Street:</label>
					        	<input type="text" id='street' name='street' value="${address?.street?.encodeAsHTML()}"/>
							</p>
							<p class='value ${hasErrors(bean:address,field:'zipcode','errors')}'>
					        	<label for='zipcode'>Zipcode:</label>
					        	<input type='text' id='zipcode' name='zipcode' value="${address?.zipcode}" />
							</p>
							<p class='value ${hasErrors(bean:address,field:'city','errors')}'>
					        	<label for='city'>City:</label>
					        	<input type="text" id='city' name='city' value="${address?.city?.encodeAsHTML()}"/>
							</p>
							<p>
	                           <label for='createdAt'>Created At:</label>
	                           <g:formatDate format="dd.MM.yyyy HH:mm" date="${user.createdAt}"/>
							</p>
			                <div class="buttons">
			                    <span class="button"><g:actionSubmit class="save" value="Update" /></span>
			                    <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>
			                </div>
	                    </div>
                        </g:form>
                        <g:uploadForm action="upload" method="post" >
                            <input type="hidden" name="id" value="${user?.id}" />
                        <div class="subdialog">
                            <h2>Image Upload</h2>
                            <p class='value ${hasErrors(bean:user,field:'password','errors')}'>
                               <label for='image'>Image:</label>
                               <input type="file" id='image' name='image'/>
                            </p>
                            <div class="buttons">
                                <span class="button"><g:actionSubmit class="save" value="Upload" /></span>
                            </div>
                        </div>
                        </g:uploadForm>
                    </div>
	            <div class="dialog">
		            <div class="subdialog">
		            	<h2>Contact Data</h2>
		                <table>
		                    <thead>
		                        <tr>
		                   	        <g:sortableColumn property="type" title="Type" />
		                   	        <g:sortableColumn property="data" title="Data" />
		                   	        <th>Action</th>
		                        </tr>
		                    </thead>
		                    <tbody>
		                    <g:each in="${user.contactData}" status="i" var="contactData">
		                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
		                            <td>${contactData.type?.encodeAsHTML()}</td>
		                            <td>${contactData.data?.encodeAsHTML()}</td>
		                            <td><span class="buttons"><g:link class="delete" controller='contactData' action='confirmDelete' id='${contactData?.id}'>delete</g:link>&nbsp;<g:link class="edit" controller='contactData' action='edit' id='${contactData?.id}'>edit</g:link></span></td>
		                        </tr>
		                    </g:each>
		                    </tbody>
		                </table>
				        <span class="buttons"><g:link class="create" controller='contactData' params='["user_id":user?.id]' action='create'>Add Contact Data</g:link></span>
	                </div>
		            <div class="subdialog">
		            	<h2>Groups</h2>
		                <table>
		                    <thead>
		                        <tr>
		                   	        <g:sortableColumn property="name" title="Group" />
		                   	        <th>Action</th>
		                        </tr>
		                    </thead>
		                    <tbody>
	                        <g:each in="${user.groups}" status="i" var="group">
								<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
	                         		<td>${group.name?.encodeAsHTML()}</td>
		                            <td><span class="buttons"><g:link class="delete" controller='user' action='deleteGroup' id='${user?.id}' params='["group_id":group?.id]'>delete</g:link></span></td>
	                            </tr>
	                        </g:each>
		                    </tbody>
		                </table>
		                <g:if test="${availableGroups.size > 0}">
		                <g:form name="userGroupForm" controller="user" action="addGroup" method="post" >
			                <input type="hidden" name="id" value="${user?.id}" />
		                	<g:select optionKey="id" from="${availableGroups}" name='group_id' />
		                    <span class="buttons"><g:actionSubmit class="create" value="Add Group" /></span>
		                </g:form>
						</g:if>
		            </div>
	            </div>
	        </div>
        </div>
		<div id="right-column">
            <g:if test="${flash.message}">
				<strong class="h">INFO</strong>
	            <div class="box">${flash.message}</div>
            </g:if>
            <g:hasErrors bean="${user}">
				<strong class="h">ERROR</strong>
                <div class="box"><g:renderErrors bean="${user}" as="list" /></div>
            </g:hasErrors>
		</div>
    </body>
</html>
